package org.example.mone.controll;


import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.HexUtil;
import org.example.mone.service.IDeployService;
import org.example.vo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admincenter")
public class DeployController {

    private static final Logger LOGGER = LoggerFactory.getLogger(DeployController.class);

    @Resource
    private IDeployService iDeployService;

    @GetMapping("/plan/deploy")
    public Result<String> deploy() {
        LOGGER.info("deploy");
        Result<String> result = iDeployService.deploy();
        return result;
    }

    @GetMapping("/plan/uninstall")
    public Result<String> uninstall() {
        LOGGER.info("uninstall");
        Result<String> result = iDeployService.uninstall();
        return result;
    }

    @GetMapping("/plan/statereport")
    public Result<String> stateReport(@RequestParam(name = "params", required = true) String taskStatus) {
        LOGGER.info("stateReport params={}",HexUtil.decodeHexStr(taskStatus, CharsetUtil.CHARSET_UTF_8));
        iDeployService.stateHandler(HexUtil.decodeHexStr(taskStatus, CharsetUtil.CHARSET_UTF_8));
        return Result.ok();
    }

}
